<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/layui/css/layui.css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
</head>
<body>
	<form id="formId" onsubmit="return false" method="post">
		ID：<input type="hidden" name="id" value="${user.id}"/><br/>
		用户名：<input type="text" name="name" value="${user.name}"/><br/>
		密码：<input type="text" name="password" value="${user.password}"/><br/>
		邮箱：<input type="text" name="email" value="${user.email}"/><br/>
		部门：<select id="selectId" name="department_id"></select><br/>
		年龄：<input type="text" name="age" value="${user.age}"/><br/>
		入职日期:<input type="text" class="layui-input" id="test1" name="joindate" value="${user.joindate}"><br/>
		<button onclick="update()">修改</button>
	</form>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js" ></script>
	<script src="<%=request.getContextPath()%>/static/lib/jquery/jquery-1.11.1.js"></script>
	<script src="${pageContext.request.contextPath}/static/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/common/mylayer.js"></script>
	<script type="text/javascript">
	 layui.use(['laydate','layer'], function(){
		  var laydate = layui.laydate;
		  var layer = layui.layer;
		  
		  //执行一个laydate实例
		  laydate.render({
		    elem: '#test1' //指定元素
		  });
		}); 
		$(function(){
			$.ajax({
				url : "${pageContext.request.contextPath}/user/getDepartmentSelect.action",
				type : "POST",
				dataType : "json",
				success : function(resp){
					console.log(resp);
					var data = resp.data;
					var userId = ${user.department_id};
					console.log("userId"+userId);
					var html = "<option>--请选择--</option>";
					for(var i =0;i < data.length;i++){
						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					$("#selectId").html(html);
					$("#selectId").val(userId);
				}
			})
			$("#selectId").val(user.department_id); 
		})
		 function update(){
			$.ajax({
				data : $("#formId").serialize(),
				type : "POST",
				dataType : "json",
				url : "${pageContext.request.contextPath}/user/userUpdate.action",
				success : function(resp){
					if(resp.code == 0){
						mylayer.success(resp.msg);
					} else {
						mylayer.error(resp.msg);
					}
				}
			})
		} 
	</script>
</body>
</html>